package servlet;

import dao.ArticleDao;
import dao.UserDao;
import dao.daoimpl.ArticleDaoImpl;
import dao.daoimpl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name="BrowseUserServlet",urlPatterns = "/BrowseUserServlet")
public class BrowseUserServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        String account=request.getParameter("browseArticleUser");
        UserDao userDao=new UserDaoImpl();
        ArticleDao articleDao=new ArticleDaoImpl();
        try {
            request.getSession().setAttribute("browseUser",userDao.getUser(account));/*返回博主*/
            request.getSession().setAttribute("browseUserArticles",articleDao.getArticles(account));/*返回博主博客信息*/
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}
